package cn.edu.zafu.bigdata.lhff;

import java.util.Arrays;
import java.util.List;

public class MaxFinder {

    public static <T extends Comparable<T>> T findMax(List<T> list) {
        if (list == null || list.isEmpty()) {
            throw new IllegalArgumentException("列表不能为空");
        }

        T max = list.get(0);
        for (T item : list) {
            if (item.compareTo(max) > 0) {
                max = item;
            }
        }
        return max;
    }

    public static void main(String[] args) {
        List<Integer> intList = Arrays.asList(1, 3, 5, 2, 4);
        Integer maxInt = findMax(intList);
        System.out.println("整数列表中的最大值: " + maxInt);

        List<String> strList = Arrays.asList("apple", "orange", "banana", "grape");
        String maxStr = findMax(strList);
        System.out.println("字符串列表中的最大值: " + maxStr);
    }
}
